﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Jacaranda.Model;

namespace QingzimaDB
{
    public class JichuDB : UpdatableEntity
    {
        /// <summary>
        /// 数据库自增主键
        /// </summary>
        [DbPrimaryKey]
        [Field]
        [AutoIncrease]
        public int ID { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [Field]
        public DateTime CreatedTime { get; set; }

        [PrimaryKey]
        [Field(Name = "KeyID")]
        public string Key { get; set; }

        public override void BeforeSave()
        {
            base.BeforeSave();
            //判断主键是否存在，不存在自动添加
            if (string.IsNullOrEmpty(Key))
            {
                Key = Guid.NewGuid().ToString();
            }
            //判断创建时间是否存在，不存在自动添加
            if (CreatedTime == null || CreatedTime == DateTime.MinValue)
            {
                CreatedTime = DateTime.Now;
            }
        }
    }
}
